<?php

/* Really simple caching class
 * Copyright (c) 2009 - Sergio Milardovich
 * GNU/GPL Licenced
 */
  class kleocache extends kleocore {

    var $cache_file;
    var $cache_dir = 'tmp/cache';
    var $cache_time = '36000';

    function cache_start($load,&$buff){
      ob_start();
      $this->cache_file = md5($_SERVER['REMOTE_ADDR'].$load);
      $file = $this->cache_dir.'/'.$this->cache_file;
      $time = @filemtime($file);
      if(file_exists($file)){
	  if ((time() - $this->cache_time) < $time) { 
	    $buff = file_get_contents($file);
	  } else {
	    $this->appreload();
	  }
      } else {
	$this->appreload();
      }
    }
    function cache_end($content){
      $fp = fopen($this->cache_dir.'/'.$this->cache_file, 'w');
      @fwrite($fp, $content);
      @fclose($fp);
      ob_end_flush();
    }
    function cache_clear(){
      $files = scandir($this->cache_dir);
      foreach($files as $file){
	if(!is_dir($file)){
	unlink($dir.'/'.$file);
	}
      }
    }
  }
?>